package com.th.supcom.pds.config.server;

import java.util.List;

import net.carefx.framework.container.client.exception.UiException;
import net.carefx.framework.util.ConvertUtils;
import net.carefx.framework.web.gwt.server.GwtController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.th.supcom.pds.config.client.model.PhamWindowConfigModel;
import com.th.supcom.pds.config.client.service.PhamWindowConfigRpc;
import com.th.supcom.pds.domain.pojo.PhamWindowConfig;
import com.th.supcom.pds.internal.api.config.PhamWindowConfigService;

/**
 * PhamWindowConfig 控制层.
 * 
 * 药房窗口属性列表.
 */
public class PhamWindowConfigServiceController extends GwtController implements PhamWindowConfigRpc
{
    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";
    /** 日志记录器. */
    public static final Logger s_logger = LoggerFactory.getLogger (PhamWindowConfigServiceController.class);

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    private static final long serialVersionUID = 1L;

    private PhamWindowConfigService m_phamWindowConfigService;

    @Override
    public void addPhamWindowConfig (final PhamWindowConfigModel phamWindowConfigModel) throws UiException
    {
        PhamWindowConfigServiceController.s_logger.debug ("call addPhamWindowConfig (PhamWindowConfigModel phamWindowConfigModel=【{}】)", phamWindowConfigModel);
        final PhamWindowConfig phamWindowConfig = ConvertUtils.convert (PhamWindowConfig.class, phamWindowConfigModel);
        try
        {
            m_phamWindowConfigService.addPhamWindowConfig (phamWindowConfig);
        }
        catch (final Exception e)
        {
            PhamWindowConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public List <PhamWindowConfigModel> findPhamWindowConfigByExample (final PhamWindowConfigModel model) throws UiException
    {
        PhamWindowConfigServiceController.s_logger.debug ("call modifyPhamWindowConfig (PhamWindowConfigModel phamWindowConfigModel=【{}】)", model);
        final PhamWindowConfig phamWindowConfig = ConvertUtils.convert (PhamWindowConfig.class, model);
        try
        {
            final List <PhamWindowConfig> list = m_phamWindowConfigService.findPhamWindowConfigByExample (phamWindowConfig);
            final List <PhamWindowConfigModel> modelList = ConvertUtils.convert (PhamWindowConfigModel.class, list);
            return modelList;
        }
        catch (final Exception e)
        {
            PhamWindowConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public PhamWindowConfigModel getPhamWindowConfigById (final Long id) throws UiException
    {
        PhamWindowConfigServiceController.s_logger.debug ("call getPhamWindowConfigById (Long id=【{}】)", id);
        try
        {
            final PhamWindowConfig phamWindowConfig = m_phamWindowConfigService.getPhamWindowConfigById (id);
            final PhamWindowConfigModel model = ConvertUtils.convert (PhamWindowConfigModel.class, phamWindowConfig);
            return model;
        }
        catch (final Exception e)
        {
            PhamWindowConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public void modifyPhamWindowConfig (final PhamWindowConfigModel phamWindowConfigModel) throws UiException
    {
        PhamWindowConfigServiceController.s_logger.debug ("call modifyPhamWindowConfig (PhamWindowConfigModel phamWindowConfigModel=【{}】)", phamWindowConfigModel);
        final PhamWindowConfig phamWindowConfig = ConvertUtils.convert (PhamWindowConfig.class, phamWindowConfigModel);
        try
        {
            m_phamWindowConfigService.modifyPhamWindowConfig (phamWindowConfig);
        }
        catch (final Exception e)
        {
            PhamWindowConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public void modifyPhamWindowConfigByExample (final PhamWindowConfigModel phamWindowConfigModel) throws UiException
    {
        PhamWindowConfigServiceController.s_logger.debug ("call modifyPhamWindowConfigByExample (PhamWindowConfigModel phamWindowConfigModel=【{}】)", phamWindowConfigModel);
        final PhamWindowConfig phamWindowConfig = ConvertUtils.convert (PhamWindowConfig.class, phamWindowConfigModel);
        try
        {
            m_phamWindowConfigService.modifyPhamWindowConfigByExample (phamWindowConfig);
        }
        catch (final Exception e)
        {
            PhamWindowConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public void removePhamWindowConfig (final Long id) throws UiException
    {
        PhamWindowConfigServiceController.s_logger.debug ("call getPhamWindowConfigById (Long id=【{}】)", id);
        final PhamWindowConfig phamWindowConfig = new PhamWindowConfig ();
        phamWindowConfig.setPhamWindowConfigId (id);
        try
        {
            m_phamWindowConfigService.removePhamWindowConfig (phamWindowConfig);
        }
        catch (final Exception e)
        {
            PhamWindowConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    public void setPhamWindowConfigService (final PhamWindowConfigService phamWindowConfigService)
    {
        m_phamWindowConfigService = phamWindowConfigService;
    }
}